<?php
/**
 * Created by PhpStorm.
 * User: aDaddy
 * Date: 2016/7/25
 * Time: 9:55
 */

namespace App\Model\LazyCommon;
use App\Model\LazyCommon\MoneyModel;
use App\Base\BaseConfig;
use App\Base\BaseModel;
use App\Model\LazyCommon\UserModel;
use App\Entity\UserInvite;
use App\Entity\UserInviteBonus;

//use App\Setting\LazyCommon\UserInviteSetting;

class UserInviteExModel extends UserInviteModel{
    public function getVipFromParent($parent,$limit = 0)
    {
        if ($limit && $limit < count($parent)) {
            $parent = array_slice($parent,0,$limit);
        }

        $qb = $this->em->createQueryBuilder();
        $qb->from("App:UserInvite","UserInvite")
            ->select("UserInvite.uid")
            ->innerJoin("App:User","User","with","User.id = UserInvite.uid")
            ->where(
                $qb->expr()->in("UserInvite.uid",$parent)
            )
            ->andWhere("User.groups = 5");
         $rst = $qb->getQuery()->getArrayResult();
        $uidArray = array();
        foreach ($rst as $row) {
            $uidArray[] = $row["uid"];
        }
        foreach ($parent as $uid) {
            if (in_array($uid,$uidArray)) {
                return $uid;
            }
        }
        return false;
    }


    public function getAgentFromParent($parent,$limit = 0)
    {
        if ($limit && $limit < count($parent)) {
            $parent = array_slice($parent,0,$limit);
        }

        $qb = $this->em->createQueryBuilder();
        $qb->from("App:UserInvite","UserInvite")
            ->select("UserInvite.uid")
            ->innerJoin("App:User","User","with","User.id = UserInvite.uid")
            ->where(
                $qb->expr()->in("UserInvite.uid",$parent)
            )
            ->andWhere("User.groups = 6");
        $rst = $qb->getQuery()->getArrayResult();
        $uidArray = array();
        foreach ($rst as $row) {
            $uidArray[] = $row["uid"];
        }
        foreach ($parent as $uid) {
            if (in_array($uid,$uidArray)) {
                return $uid;
            }
        }
        return false;
    }

}